package birs.controller.expanditure;

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import birs.controller.expanditure.task.XPD001Task;
import birs.util.ConnectionDB;

/**
 * Servlet implementation class XPD001Controller2
 */
@WebServlet("/XPD001Controller")
public class XPD001Controller extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public XPD001Controller() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// try-with-closable-resource java.sql.Connection, automatic close Connection when Task finished
		try (Connection regCon = ConnectionDB.getRegConnection()) {
			XPD001Task xpd001Task = new XPD001Task(regCon);

			if(request.getParameter("stdPeriod")==null){
				xpd001Task.getExpanditure(request, response);
			}else if((request.getParameter("stdPeriod")!=null) && (request.getParameter("acadYear")!=null)){
				xpd001Task.getFirstDrilldown(request, response);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}
}